'''
Created on Apr 29, 2011

@author: Jialai_Zhu
'''

import os
if __name__ == '__main__':
    def main():
        import sys
        c=len(sys.argv)
        if c<4:
            return
        i=1
        files=[]
        output=open(sys.argv[c-1],'wb')
        while i<c-1:
            print i,sys.argv[i]
            try:
                files.append(open(sys.argv[i],'rb'))
                i=i+1
            except:
                pass
        if len(files)<2:
            print 'at least two key file'
    
        words=[]
        for f in files:
            temp_words=[]
            new_words=[]
            for w in f.readlines():
                import string
                w=string.replace(w, '\r\n', '')
                temp_words.append(w)
            for w in words:
                for tw in temp_words:
                    new_words.append(('"%s"  "%s"')%(w,tw))
            if len(new_words)==0:
                new_words=temp_words
            words=[]
            words=new_words
        print words
        for object in words:
            output.write(object+'\r\n')
    main()